package com.gs.wzmanager.service.impl;

import com.gs.wzmanager.dao.UserDao;
import com.gs.wzmanager.entity.Resource;
import com.gs.wzmanager.entity.Role;
import com.gs.wzmanager.entity.User;
import com.gs.wzmanager.service.UserService;
import com.gs.wzmanager.shiroconfig.PasswordHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserDao userDao;


    public void addUser(User user) {
        //md5加盐（phone）
        user.setPassword(PasswordHelper.md5Pwd(user.getPassword(),user.getPhone()));
        userDao.addUser(user);
    }

    public void addUserRole(String userId, int roleId) {
        userDao.addUserRole(userId, roleId);
    }

    public void updateSimpleUser(User user) {
        userDao.updateSimpleUser(user);
    }

    public User queryUserById(String id) {
        return userDao.queryUserById(id);
    }

    public User queryUserByPhone(String phone) {
        return userDao.queryUserByPhone(phone);
    }

    public List<User> queryUserByName(String name) {
        return userDao.queryUserByName(name);
    }
    public List<User> queryAllUser() {
        return userDao.queryAllUser();
    }

    public List<Resource> queryResourceByUserId(String userId) {
        return userDao.queryResourceByUserId(userId);
    }

    public List<Role> queryRoleByUserId(String userId) {
        return userDao.queryRoleByUserId(userId);
    }

    public void deleteUser(String id) {
        userDao.deleteUser(id);
    }

    public void deleteUserRoleByUserId(String userId) {
        userDao.deleteUserRoleByUserId(userId);
    }
}
